//
//  YYMusciCommentTableViewCell.swift
//  STMusic
//
//  Created by stoneobs on 17/4/19.
//  Copyright © 2017年 stoneobs. All rights reserved.
////**********************这是乐评cell***************************

import UIKit

// MARK:乐评cell,包含语音
class YYMusciCommentCell: UITableViewCell {
    
    var model:YYRecommendModel? {
    
        didSet{
        
            self.headView?.model = self.model;
            
            self.commentView?.model = self.model;
            
            
        }
    
    }
    
    var headView:YYFrequentlyUserCellHeader?
    
    var commentView:YYFrequentlyMusicCommentView?
    
    var scanDetailButton:STButton?
    
    
    static var YYMusciCommentCellHeight:CFloat = 120;
    
    
    override  init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier);
        self.initSubview();
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubview() {
        
        self.headView = YYFrequentlyUserCellHeader.init(frame: .init(x: 0, y: 0, width: SCREEN_WIDTH, height: 50));
        self.headView?.backgroundColor = .white;
        self.addSubview(self.headView!);
        
        self.commentView = YYFrequentlyMusicCommentView.init(frame: CGRect.init(x: (self.headView?.nickNameLabel?.left)!, y: (self.headView?.bottom)! + 5, width: SCREEN_WIDTH - 15 - (self.headView?.nickNameLabel?.left)!, height: 25));
        self.addSubview(self.commentView!);
        
        self.scanDetailButton = STButton.init(frame: CGRect.init(x: (self.commentView?.left)!, y: (self.commentView?.bottom)! + 10, width: 100, height: 14), title: "查看详情", titleColor: YYThemeStyleManger.defultManger.backeGroundColor, titleFont: 14, cornerRadius: 0, backgroundColor: nil, backgroundImage: nil, image: nil);
        
        self.addSubview(self.scanDetailButton!);
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
// MARK:回复cell，只能回复一次，继续回复添加一条cell
class YYReplyCommentCell: UITableViewCell {
    
    var YYCommentCellHeight:CGFloat?

    var model:YYCommentModel? {
        
        didSet{
            
            self.headView?.commentModel = self.model;
            
            if  (model?.words) != nil {
                //回复内容
                let attributedStrM : NSMutableAttributedString = NSMutableAttributedString()
                
                let huifu : NSAttributedString = NSAttributedString(string: "回复", attributes: [ NSBackgroundColorAttributeName : UIColor.clear,NSForegroundColorAttributeName : UIColor.black, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 13)])
                let originName = "@\((model?.origin_comment?.user?.nickname)!)"
                let name : NSAttributedString = NSAttributedString(string: originName, attributes: [ NSBackgroundColorAttributeName : UIColor.clear,NSForegroundColorAttributeName : UIColor.flatBlueDark, NSFontAttributeName : UIFont.boldSystemFont(ofSize: 13)])

                let comment:NSAttributedString = NSAttributedString.init(string: (model?.words)!);
                
                attributedStrM.append(huifu);
                attributedStrM.append(name);
                attributedStrM.append(comment);
                
                let finshComment:NSString = attributedStrM.string as NSString;
                
                let height = finshComment.heigthWithwidth((self.commentLable?.width)!, font: 14);
               
                self.commentLable?.height = height;
                self.commentLable?.numberOfLines = 0;
                
                self.commentLable?.attributedText = attributedStrM;
            }
            

            if model?.origin_comment?.words != nil {
                self.originCommentButton?.top = (self.commentLable?.bottom)! + 10;
                
                self.originCommentButton?.contentHorizontalAlignment = .left;
                
                let title:NSString = ((model?.origin_comment?.user?.nickname)! + ":" +  (model?.origin_comment?.words)!) as NSString;
                let height = title.heigthWithwidth((self.originCommentButton?.width)!, font: 13);
                
                self.originCommentButton?.titleLabel?.numberOfLines = 0;
                self.originCommentButton?.height = height + 5;
                
                self.originCommentButton?.titleEdgeInsets = .init(top: 0, left: 3, bottom: 0, right: 0);
                self.originCommentButton?.setTitle(title as String , for: .normal);
                
                self.originCommentButton?.backgroundColor = YYThemeStyleManger.defultManger.gradualColor(frame: (self.originCommentButton?.bounds)!);
                
            }
            
            self.YYCommentCellHeight = (self.originCommentButton?.bottom)! + CGFloat(20.0);
            
        }
        
    }
    
    var headView:YYFrequentlyUserCellHeader?//头部
    
    var commentLable:STLabel?//内容
    
    var originCommentButton:STButton?//原始评论按钮
    
    
    override  init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier);
        self.initSubview();
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubview() {
        self.headView = YYFrequentlyUserCellHeader.init(frame: .init(x: 0, y: 0, width: SCREEN_WIDTH, height: 50));
        self.headView?.backgroundColor = .white;
        self.addSubview(self.headView!);
        
        self.commentLable = STLabel.init(frame: CGRect.init(x: (self.headView?.nickNameLabel?.left)!, y: (self.headView?.bottom)! + 5, width: SCREEN_WIDTH - 15 - (self.headView?.nickNameLabel?.left)!, height: 25),
                                         text: "",
                                         textColor: FirstTextColor,
                                         font: 14,
                                         isSizetoFit: false,
                                         textAlignment: .left);
        self.commentLable?.numberOfLines = 0;
        self.addSubview(self.commentLable!);
        
        self.originCommentButton = STButton.init(frame: CGRect.init(x: (self.headView?.nickNameLabel?.left)!, y: 20, width: SCREEN_WIDTH - 15 - (self.headView?.nickNameLabel?.left)!, height: 40),
                                                 title: "",
                                                 titleColor: FlatBlack(),
                                                 titleFont: 13,
                                                 cornerRadius: 0,
                                                 backgroundColor: FlatWhiteDark(),
                                                 backgroundImage: nil,
                                                 image: nil);
        self.addSubview(self.originCommentButton!);

    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}

// MARK:评论cell 无乐评
class YYCommentCell: UITableViewCell {
    static var YYCommentCellHeight:CFloat = 100;
    var model:YYCommentModel? {
        
        didSet{
            
            self.headView?.commentModel = self.model;
            
            self.commentLable?.text = model?.words;
         
            if self.commentLable?.text == "已评分" {
                self.commentLable?.width = 50;
                self.scoreView?.left = (self.commentLable?.right)! + 10;
                self.scoreView?.isHidden = false;
                self.scoreView?.difficultyNum = model!.score as! Int;
            }else{
                //let comment:NSString = NSString.init(string: (model?.words)!);
                self.commentLable?.width = SCREEN_WIDTH - 15 - (self.headView?.nickNameLabel?.left)!
                
                
              self.scoreView?.isHidden = true;
            }
            
        }
        
    }
    
    var headView:YYFrequentlyUserCellHeader?//头部
    
    var commentLable:STLabel?//内容
    
    var scoreView:STXingXIngView?//难度分值1-10，如果是已评分则隐藏
    
    
    override  init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier);
        self.initSubview();
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    func initSubview() {
        self.headView = YYFrequentlyUserCellHeader.init(frame: .init(x: 0, y: 0, width: SCREEN_WIDTH, height: 50));
        self.headView?.backgroundColor = .white;
        self.addSubview(self.headView!);
        
        self.commentLable = STLabel.init(frame: CGRect.init(x: (self.headView?.nickNameLabel?.left)!, y: (self.headView?.bottom)! + 5, width: SCREEN_WIDTH - 15 - (self.headView?.nickNameLabel?.left)!, height: 25),
                                         text: "",
                                         textColor: FirstTextColor,
                                         font: 14,
                                         isSizetoFit: false,
                                         textAlignment: .left);
        self.addSubview(self.commentLable!);
        
        self.scoreView = STXingXIngView.init(frame: .init(x: 10 + (commentLable?.right)!, y: 0, width: 160, height: 15));
        self.scoreView?.isHidden = true;
        self.scoreView?.centerY = (self.commentLable?.centerY)!;
        self.addSubview(self.scoreView!);
        
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
}
